package com.xxwy.springcloud;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.actuate.health.Health;
import org.springframework.boot.actuate.health.HealthIndicator;
import org.springframework.boot.actuate.health.Status;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.context.refresh.ContextRefresher;
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;
import org.springframework.context.annotation.Bean;
import org.springframework.scheduling.annotation.Scheduled;

import java.util.Set;

/**
 * @author xxwy
 * on 2018/9/29 0029
 */
@SpringBootApplication
@EnableEurekaServer
@EnableDiscoveryClient
public class EurekaServer7001_App {

//    private final ContextRefresher contextRefresher;
//
//    @Autowired
//    public EurekaServer7001_App(ContextRefresher contextRefresher) {
//        this.contextRefresher = contextRefresher;
//    }
//
//    @Scheduled(fixedRate = 1000L)
//    public void update(){
//        Set<String> refresh = contextRefresher.refresh();
//        if (!refresh.isEmpty()) {
//            System.out.println("本次更新的配置型" + refresh);
//        }
//    }

    public static void main(String[] args) {
        SpringApplication.run(EurekaServer7001_App.class,args);
    }

    @Bean
    public MyHealthIndicator myHealthIndicator() {
        return new MyHealthIndicator();
    }

    private class MyHealthIndicator implements HealthIndicator {

        @Override
        public Health health() {
            Health.Builder builder = Health.status(Status.UP);
            builder.withDetail("name", "MyHealthIndicator");
            builder.withDetail("timestamp", System.currentTimeMillis());
            return builder.build();
        }
    }
}
